<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

</body>
<script>
    let arr1 = [1, 2, 3,new Date()];

    // 等号赋值是浅拷贝
    let arr2 = arr1;
    arr2[0] = 4

    // 深拷贝
    let arr3 = [].concat(arr1);
    arr3[0] = 6

    // 暴力深拷贝
    let arr4 = JSON.parse(JSON.stringify(arr1));
    arr4[0] = 9

    // es6拷贝
    let arr5 = [...arr1];
    arr5[0] = 10

    console.log(arr1 +"=="+ arr2 +"=="+ arr3  +"=="+ arr4  +"=="+ arr5)

    let obj1 = {
        name : '小明',
        birth: new Date()
    }

    // 等号赋值是浅拷贝
    let obj2 = obj1
    obj2.name = '小狗'

    // 暴力深拷贝
    let obj3 = JSON.parse(JSON.stringify(obj1));
    obj3.name = '小猫'

    // es6深拷贝
    let obj4 = {...obj1}
    obj4.name = '小猪'
    console.log(obj1)
    console.log(obj2)
    console.log(obj3)
    console.log(obj4)
</script>
</html>
